<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_labelVectorLayerData"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
            border: 1px solid #3473b7;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.text_labelVectorLayerData"></h5></div>
    <div class='panel-body content'>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_addData"
               onclick="addData()"/>&nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_removeData"
               onclick="removeData()"/>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script type="text/javascript">

    var map, layer, dataAdded = false,
        host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090",
        url = host + "/iserver/services/map-world/rest/maps/World";
    init();

    function init() {
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation(),
            ]
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        map.addControl(new SuperMap.Control.MousePosition());
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, null, {maxResolution: "auto"});
        vector = new SuperMap.Layer.Vector("vector");
        layer.events.on({"layerInitialized": addLayer});
        addData();
    }

    function addLayer() {

        map.addLayers([layer, vector]);
        map.setCenter(new SuperMap.LonLat(0, 0), 0);
    }

    function addData() {
        if (!dataAdded) {
            vector.removeAllFeatures();
            //画两个圆
            var centerPoint1 = new SuperMap.Geometry.Point(-98, 41);
            var circleP1 = createCircle(centerPoint1, 30, 256, 360, 360);
            var circleVector1 = new SuperMap.Feature.Vector(circleP1);
            circleVector1.style = {
                strokeColor: "#CAFF70",
                fillColor: "#DC143C",
                strokeWidth: 2,
                fillOpacity: 0.8,
                label: "西方\nWestern",
                fontColor: "#FFF0F5"
            };
            var centerPoint2 = new SuperMap.Geometry.Point(103, 38);
            var circleP2 = createCircle(centerPoint2, 30, 256, 360, 360);
            var circleVector2 = new SuperMap.Feature.Vector(circleP2);
            circleVector2.style = {
                strokeColor: "#CAFF70",
                fillColor: "#DC143C",
                strokeWidth: 2,
                fillOpacity: 0.8,
                fontWeight: "bold",
                label: "东方\n Eastern",
                fontColor: "#FFF0F5"

            };
            vector.addFeatures([circleVector1, circleVector2]);
            dataAdded = true;
        } else {
            widgets.alert.showAlert(resources.msg_loadedData, true);
        }
    }

    //Բ
    function createCircle(origin, radius, sides, r, angel) {
        var rR = r * Math.PI / (180 * sides);
        var rotatedAngle, x, y;
        var points = [];
        for (var i = 0; i < sides; ++i) {
            rotatedAngle = rR * i;
            x = origin.x + (radius * Math.cos(rotatedAngle));
            y = origin.y + (radius * Math.sin(rotatedAngle));
            points.push(new SuperMap.Geometry.Point(x, y));
        }
        rotatedAngle = r * Math.PI / 180;
        x = origin.x + (radius * Math.cos(rotatedAngle));
        y = origin.y + (radius * Math.sin(rotatedAngle));
        points.push(new SuperMap.Geometry.Point(x, y));

        var ring = new SuperMap.Geometry.LinearRing(points);
        ring.rotate(parseFloat(angel), origin);
        var geo = new SuperMap.Geometry.Collection([ring]);
        geo.origin = origin;
        geo.radius = radius;
        geo.r = r;
        geo.angel = angel;
        geo.sides = sides;
        geo.polygonType = "Curve";
        return geo;
    }

    function removeData() {
        widgets.alert.clearAlert();
        dataAdded = false;
        vector.removeAllFeatures();
        vector.refresh();
    }

</script>

</body>
</html>